Micron Document
NexusPi Git Node


Displaying Raw • Download

native/reboot.cpp fc463eb4c579bbcd7340546e598044bd8345f3a5 (fc463eb4) Text, 2.48 KB

T8b949e// Copyright (C) 2026, microReticulum_Firmware contributors
T8b949e//
T8b949e// See reboot.h for the deferred-reboot rationale. Cleanup sequence mirrors
T8b949e// meshtasticd's Power::reboot() (src/Power.cpp:711-737 in their tree):
T8b949e// notify, close API server, release peripheral handles, SPI.end(), reboot().
T8b949e// Our daemon doesn't have a notification observer pattern yet, so we skip
T8b949e// that step.

Tff7b72#Tff7b72include T8b949e"reboot.h"

Tff7b72#Tff7b72include T8b949e"EEPROMShim.h"
Tff7b72#Tff7b72include T8b949e"TCPHostInterface.h"

Tff7b72#Tff7b72include T8b949e<Arduino.h>T8b949e // void reboot(); extern HardwareSPI SPI;

Tff7b72#Tff7b72include T8b949e<cstdio>
Tff7b72#Tff7b72include T8b949e<cstdlib>

Tff7b72namespace T7ee787native_pinmap Tb4b4b4{
T8b949e// Defined in PinMap.cpp. No-op on macOS, releases libgpiod handles
T8b949e// on Linux by rebinding each previously-bound pin to a SimGPIOPin
T8b949e// (which triggers ~LinuxGPIOPin → gpiod_line_release).
Tffa657void Td2a8ffrelease_linux_gpiosTb4b4b4(Tb4b4b4)Tb4b4b4;
Tb4b4b4}

Tff7b72namespace T7ee787native_reboot Tb4b4b4{

Tff7b72namespace Tb4b4b4{
Tffa657bool Te6edf3reboot_flag Tff7b72= Tffa657falseTb4b4b4;
Tb4b4b4}

Tffa657void Te6edf3requestTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3reboot_flagTb4b4b4) Tb4b4b4{
Te6edf3stdTff7b72:Tff7b72:Te6edf3fprintfTb4b4b4(Te6edf3stderrTb4b4b4,
Ta5d6ff"Ta5d6ff[reboot] requested — will re-exec on next loop tickTffea00\nTa5d6ff"Tb4b4b4)Tb4b4b4;
Tb4b4b4}
Te6edf3reboot_flag Tff7b72= Tffa657trueTb4b4b4;
Tb4b4b4}

Tffa657bool Te6edf3pendingTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72return Te6edf3reboot_flagTb4b4b4;
Tb4b4b4}

Tb4b4b4[Tb4b4b4[Te6edf3noreturnTb4b4b4]Tb4b4b4] Tffa657void Te6edf3performTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3stdTff7b72:Tff7b72:Te6edf3fprintfTb4b4b4(Te6edf3stderrTb4b4b4, Ta5d6ff"Ta5d6ff[reboot] tearing down and re-execing daemonTffea00\nTa5d6ff"Tb4b4b4)Tb4b4b4;

T8b949e// Defensive flush. Most config-save paths in Utilities.h call
T8b949e// EEPROM.commit() before hard_reset(), but a missed call site would
T8b949e// otherwise lose the property write on re-exec.
Te6edf3EEPROMTb4b4b4.Te6edf3commitTb4b4b4(Tb4b4b4)Tb4b4b4;

T8b949e// Close the KISS-over-TCP listener + active client so the re-exec'd
T8b949e// process can re-bind the same port without waiting for TIME_WAIT.
Te6edf3native_kiss_tcpTff7b72:Tff7b72:Te6edf3shutdownTb4b4b4(Tb4b4b4)Tb4b4b4;

T8b949e// Release libgpiod chip/line handles. Without this, the re-exec'd
T8b949e// process fails to re-acquire the same lines (EBUSY).
Te6edf3native_pinmapTff7b72:Tff7b72:Te6edf3release_linux_gpiosTb4b4b4(Tb4b4b4)Tb4b4b4;

T8b949e// Let Portduino tear down the SimSPIChip (cross_platform) or the
T8b949e// /dev/spidev binding (Linux).
Te6edf3SPITb4b4b4.Te6edf3endTb4b4b4(Tb4b4b4)Tb4b4b4;

Te6edf3stdTff7b72:Tff7b72:Te6edf3fprintfTb4b4b4(Te6edf3stderrTb4b4b4, Ta5d6ff"Ta5d6ff[reboot] re-exec...Tffea00\nTa5d6ff"Tb4b4b4)Tb4b4b4;
Tff7b72:Tff7b72:Te6edf3rebootTb4b4b4(Tb4b4b4)Tb4b4b4; T8b949e// Portduino's reboot() — execv(argv[0], argv).

T8b949e// Portduino's reboot() calls exit(EXIT_FAILURE) on execv failure, so
T8b949e// this should be unreachable. [[noreturn]] still requires we don't
T8b949e// fall through, so terminate explicitly.
Te6edf3stdTff7b72:Tff7b72:Te6edf3abortTb4b4b4(Tb4b4b4)Tb4b4b4;
Tb4b4b4}

Tb4b4b4} T8b949e// namespace native_reboot

Tffa657void Te6edf3native_request_rebootTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3native_rebootTff7b72:Tff7b72:Te6edf3requestTb4b4b4(Tb4b4b4)Tb4b4b4;
Tb4b4b4}

Tffa657bool Te6edf3native_reboot_pendingTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72return Te6edf3native_rebootTff7b72:Tff7b72:Te6edf3pendingTb4b4b4(Tb4b4b4)Tb4b4b4;
Tb4b4b4}

Tb4b4b4[Tb4b4b4[Te6edf3noreturnTb4b4b4]Tb4b4b4] Tffa657void Te6edf3native_reboot_performTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3native_rebootTff7b72:Tff7b72:Te6edf3performTb4b4b4(Tb4b4b4)Tb4b4b4;
Tb4b4b4}

Served by rngit 1.5.4 - Generated in 0.01s